/**
 * Copyright (c) 2009 Cerner Corporation.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    Cerner Corporation - initial API and implementation
 */
package com.cerner.system.rest.resource.organizer.spi;

import com.cerner.system.rest.resource.organizer.ResourceController;

/**
 * SPI abstract base class useful for all {@link ResourceController}
 * implementations. It overrides the {@link #hashCode()},
 * {@link #equals(Object)} and {@link #toString()} methods by using the
 * {@link ResourceController#uri()} value.
 * 
 * @author Alex Horn
 * @param <E> class type of the object that is stored in the organizer
 */
public abstract class AbstractResourceController<E> implements
    ResourceController<E> {

  @Override
  public final boolean equals(final Object object) {
    if (this == object) {
      return true;
    } else if (object instanceof ResourceController<?>) {
      final ResourceController<?> other = (ResourceController<?>) (object);

      /* other is not null */
      return uri().equals(other.uri());
    } else {
      return false;
    }
  }

  @Override
  public final int hashCode() {
    return uri().hashCode();
  }

  @Override
  public String toString() {
    return uri().toString();
  }
}
